package hu.debrecen.adastra.card.web;

import hu.debrecen.adastra.card.service.SocialUserService;
import hu.debrecen.adastra.card.web.domain.JsonException;
import hu.debrecen.adastra.card.web.domain.UserSocialReference;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.SessionAttributes;

@SessionAttributes(types = UserSocialReference.class)
public abstract class AbstractController {

	private static final Logger LOGGER = LoggerFactory.getLogger(AbstractController.class);

	protected final SocialUserService socialUserService;

	public AbstractController(final SocialUserService socialUserService) {
		super();
		this.socialUserService = socialUserService;
	}

	@ExceptionHandler(Exception.class)
	@ResponseBody
	@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
	public JsonException handleException(final Exception ex) {
		AbstractController.LOGGER.error(ex.getMessage(), ex);
		return new JsonException(ex.getClass().getCanonicalName(), ex.getMessage());
	}

}
